var prefix = jsctx + "/parking";

var parkingSupplier = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 80;

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageTenantParkingSupplier",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    cache: false,
                    pageSize: 20,
                    pageList: [10, 20, 30],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    // rightFixedColumns: true,
                    // showColumns: true,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            supplierName: $("#supplierName").val().trim(),
                            brandName: $("#brandName").val().trim(),
                            status: $("#status").val().trim(),
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'supplierCode', title: '供应商代码', align: 'center'},
                        {field: 'supplierName', title: '供应商名称', align: 'center'},
                        {field: 'brandName', title: '品牌名称', align: 'center'},
                        {field: 'contactName', title: '联系人名字', align: 'center'},
                        {field: 'phone', title: '联系人电话', align: 'center'},
                        {field: 'address', title: '公司地址', align: 'center'},
                        {field: 'status', title: '状态', align: 'center'},
                        {field: 'createdTime', title: '创建时间', align: 'center'},
                        {
                            title: '操作',
                            field: 'roleId',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var a = '';
                                if (OperationsManagement_parkingSupplier_update) {
                                    a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" onclick="parkingSupplier.parkingGateStation(\''
                                        + row.tenantCode + '\',' + row.parkingSupplierId + ')">合作站点</a> ';
                                }
                                return a;
                            }
                        }
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        window.history.back();
    }

    function parkingGateStation(tenantCode, parkingSupplierId) {
        location.href = prefix + "/parkingGateStation?tenantCode=" + tenantCode + "&parkingSupplierId=" + parkingSupplierId;
    }

    function addParkingSupplier() {
        location.href = prefix + "/addParkingSupplier";
    }


    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        parkingGateStation: parkingGateStation,
        addParkingSupplier: addParkingSupplier
    };
})();

